﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ehai.Web.Framework.Rules
{
    static class ReturnStringFromArray
    {

        private static void jLastChar(StringBuilder sb)
        {
            if (sb.Length > 1)
            {
                if (sb[sb.Length - 1] == ',')
                    sb.Remove(sb.Length - 1, 1);                
            }
        }

        // 传一维数组返回字符串
        public static string ReStringFromOneDmArr(string[] oneDmArr)
        {
            StringBuilder re = new StringBuilder();

            re.Append("[");
            for (int i = 0; i < oneDmArr.Length; i++)
            {
                re.Append("\"");
                if (oneDmArr[i] != null)
                    re.Append(UtilTools.TwiceEscapeString(oneDmArr[i]));

                re.Append("\",");
            }
            jLastChar(re);
            re.Append("]");

            return re.ToString();
        }

        // 传二维数组返回字符串
        public static string ReStringFromTwoDmArr(string[][] twoDmArr)
        {
            StringBuilder re = new StringBuilder();

            re.Append("[");
            for (int i = 0; i < twoDmArr.Length; i++)
            {
                if (twoDmArr[i] != null)
                {
                    re.Append(ReStringFromOneDmArr(twoDmArr[i]));
                    re.Append(",");
                }
            }
            jLastChar(re);
            re.Append("]");
            return re.ToString();
        }

        // 传三维数组返回字符串
        public static string ReStringFromThreeDmArr(string[][][] threeDmArr)
        {
            StringBuilder re = new StringBuilder();

            re.Append("[");
            for (int i = 0; i < threeDmArr.Length; i++)
            {
                if (threeDmArr[i] != null)
                {
                    re.Append(ReStringFromTwoDmArr(threeDmArr[i]));
                    re.Append(",");
                }
            }
            jLastChar(re);
            re.Append("]");

            return re.ToString();
        }


    }
}
